package today.rocky.boot.eureka.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * @author Rocky
 * @date 2020/2/25 21:30
 */
@RestController
public class RegisterController {


    @Autowired
    private DiscoveryClient discoveryClient;


    @GetMapping("/services")
    public Set<String> getService(){
        return new LinkedHashSet<>(discoveryClient.getServices());
    }

    @GetMapping("/services/{serviceName}")
    public List<ServiceInstance> getServiceInstance(@PathVariable String serviceName){
        return discoveryClient.getInstances(serviceName);
    }
}
